﻿Public Class NewDetail1
    Inherits CoreClass

    Protected Sub Page_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Try
            getNew()
            getOtherNews()
        Catch ex As Exception

        End Try
        
    End Sub

    ' Get dữ liệu của New fill vào form
    Private Sub getNew()
        Try
            Dim id As Integer = 0
            id = Integer.Parse(Request.QueryString("idNew"))
            If id <= 0 Then
                Response.Redirect("/")
                Exit Sub
            End If
            sql = "spi_NewGetByID " & objFunction.ValueCheck(id)
            objData.ExeReader(sql)
            If objData.dataRead.Read Then
                detailTitle.InnerHtml = objData.dataRead("NewTitle").ToString()
                Page.Title = objData.dataRead("NewTitle").ToString()
                Dim d1 As Date = Date.Parse(objData.dataRead("NewDate").ToString())
                Dim strSaveFolder As String = "/EditorData/image" & Format(d1, "/yyyy/MM/dd/")
                ProImage.ImageUrl = strSaveFolder & objData.dataRead("NewImage2").ToString()
                detailContent.InnerHtml = objData.dataRead("NewDetail").ToString()
                spanDetailTime.InnerHtml = objFunction.formatDateTimeToTemplate(objData.dataRead("NewDate").ToString(), "DoW, DD/MM/YYYY hh:mm")

                ' Set facebook info
                objFunction.Set_Page_FB(Page, HttpContext.Current.Request.Url.AbsoluteUri, objData.dataRead("NewTitle").ToString(), objConfig.Domain & strSaveFolder & objData.dataRead("NewImage2").ToString(), objData.dataRead("NewDesc").ToString())

            End If
        Catch ex As Exception
            If objConfig.Developer.Equals("1") Then
                objAlert.ErrorBox(Page, "File: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.DeclaringType.Name & _
                                  " --- Function: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.Name & _
                                  " --- Mess: " & ex.Message.Replace("'", """"))
            Else
                objAlert.ErrorBox(Page, "Lỗi kỹ thuật, hãy thông báo lại với Admin, xin cảm ơn.")
            End If
        End Try
    End Sub

    Public Sub getOtherNews()
        Try
            Dim id As Integer = 0
            id = Integer.Parse(Request.QueryString("idNew"))
            '@SubCatID nvarchar(5), --> Neu = 0 la lay tat ca tin 
            '@NotID nvarchar(50) --> Truyen vao ID bai hien tai de check trung
            '@No nvarchar(5) --> so luong tin hien thi
            sql = "spo_NewGetListOther "
            sql &= objFunction.FieldCheck(0) & ", "
            sql &= objFunction.FieldCheck(id) & ", "
            sql &= objFunction.FieldCheck(5)

            Dim dts As DataSet = objDataRead.ExeDataset(sql)
            ' Đưa dữ liệu của bảng 0 vào Repeater
            RepeatItems.DataSource = dts.Tables(0)
            RepeatItems.DataBind()
            RepeatItems.Dispose()
            
        Catch ex As Exception
            If objConfig.Developer.Equals("1") Then
                objAlert.ErrorBox(Page, "File: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.DeclaringType.Name & _
                                  " --- Function: " & (New System.Diagnostics.StackTrace).GetFrame(0).GetMethod.Name & _
                                  " --- Mess: " & ex.Message.Replace("'", """"))
            Else
                objAlert.ErrorBox(Page, "Lỗi kỹ thuật, hãy thông báo lại với Admin, xin cảm ơn.")
            End If
        End Try
    End Sub

    ' Build link đến chi tiết sản phẩm dựa trên tên danh mục, tên sp, id sp
    Public Function buildLinkDetailPro(ByVal cateName As String, ByVal proName As String, ByVal proId As String) As String
        'Return "/tin-tuc/" & cateName & "/" & proName & "-" & proId
        Return "/NewDetail.aspx?idNew=" & proId
    End Function

    ' Build src image
    Public Function buildImage(ByVal strDate As String, ByVal strImage As String) As String
        Return objFunction.buildImageByDate(strDate, strImage)
    End Function

    ' format phan Gioi thieu tin, giới hạn 200 ký tự
    Public Function getDesc(ByVal strTmp As String) As String
        Return objFunction.CutStringByInterger(strTmp, 200)
    End Function

    'format time cho tin bai
    Public Function buildTime(ByVal strTime As String, ByVal temp As String) As String
        Return objFunction.formatDateTimeToTemplate(strTime, temp)
    End Function

    'format date cho tin bai
    Public Function buildDate(ByVal strTime As String, ByVal temp As String) As String
        Return objFunction.formatDateTimeToTemplate(strTime, temp)
    End Function
End Class